package jfinal;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.Const;
import com.jfinal.ext.handler.UrlSkipHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.packages.controller.*;
import com.packages.model.*;

import jfinal.controller.IndexController;
import jfinal.handle.JspHandler;

public class AppConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		me.setMaxPostSize(100 * Const.DEFAULT_MAX_POST_SIZE);
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
		me.setError404View("/page/error/404.jsp");
		/*me.setError500View("/page/error/500.jsp");*/
	}

	@Override
	public void configHandler(Handlers arg0) {
		// TODO Auto-generated method stub
		//略过service的请求(此处为发布webservice接口)
		arg0.add(new UrlSkipHandler(".*/websocket.*",false));
		//略过service的请求(此处为发布webservice接口)
		arg0.add(new JspHandler());
	}

	@Override
	public void configInterceptor(Interceptors arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		C3p0Plugin c3p0Plugin = new C3p0Plugin(
				"jdbc:mysql://127.0.0.1:3306/spr?characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false", 
				"root", 
				"123456");
		me.add(c3p0Plugin);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		arp.setShowSql(true);//debug Sql
		arp.setContainerFactory(new CaseInsensitiveContainerFactory(true)); //大小写不敏感		
		me.add(arp);
		//arp.addMapping("menu", Menu.class);
		

	}

	@Override
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		me.add("/",IndexController.class);
		//后台
		
	}

}
